//////////////////////////////////////////
//
//	FlexInc. 2012
//	http://www.loziosecchi.it/flex_inc
//	http://twitter.com/loziosecchi
//
//////////////////////////////////////////

package flexInc.ane.android.calculatorLauncher;

import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.widget.Toast;

import com.adobe.fre.FREContext;
import com.adobe.fre.FREFunction;
import com.adobe.fre.FREObject;
import com.adobe.fre.FREWrongThreadException;

public class CalculatorLuncherOpenFunction implements FREFunction {

	@Override
	public FREObject call(FREContext context, FREObject[] args) {

		FREObject returnValue = null;
		
		try
		{
			Intent intent = new Intent();
			Activity activity = context.getActivity();
			intent.setClassName("com.android.calculator2", "com.android.calculator2.Calculator");
			activity.startActivity(intent);
				
			returnValue = FREObject.newObject(true);					
		}catch (FREWrongThreadException e) {
			Toast.makeText(context.getActivity(), e.getMessage(), Toast.LENGTH_LONG).show();									
		}catch (ActivityNotFoundException e) {
			Toast.makeText(context.getActivity(), e.getMessage(), Toast.LENGTH_LONG).show();									
		}catch (Error e) {
			Toast.makeText(context.getActivity(), "Error: " + e.getMessage(), Toast.LENGTH_LONG).show();			
		}

		return returnValue;
	}
}
